/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.submit;

import net.bioteam.appweb.TestConfig;
import net.bioteam.appweb.model.BeanshellProgramModifier;
import net.bioteam.appweb.model.Program;
import net.bioteam.appweb.model.ProgramBuilder;
import junit.framework.TestCase;

public class RdemoTest extends TestCase
{

	public RdemoTest(String name) {
		super(name);
	}

	public void setUp() throws Exception {
		TestConfig.init();
		 BeanshellProgramModifier modifier=new BeanshellProgramModifier();
         ProgramBuilder.modifiers.add(modifier);
	}


	protected void tearDown() throws Exception {
		TestConfig.shutdown();
	}

	public static void main(String args[]) {
		RdemoTest test = new RdemoTest(
				"testRdemo");
		junit.textui.TestRunner.run(test);
	}

	public static void testRdemo() throws Exception
	{
		ProgramBuilder.cache.remove("rdemo");

		Program program = ProgramBuilder.getProgram("rdemo");
		ProgramValueBean bean = new ProgramValueBean(program);
		java.util.Properties p = new java.util.Properties();
		p.setProperty("file.resource.loader.path", "d:/cmdportal/cmdwork/cmdtmpl");
		org.apache.velocity.app.Velocity.init(p);
		
		
		GeneratorUtil.generators.add(new net.bioteam.appweb.submit.TemplateGenerator());

		assertNotNull(bean.getValue("_CMD_GENERATOR"));
		assertNotNull(bean.getValue("_CMD_TEMPLATE"));
		
		bean.setValue("first", "5");
		bean.setValue("second", "6");
		
		CommandGenerator generator=GeneratorUtil.getCommandGenerator(bean);
		UnfinishedJob job=new UnfinishedJob();
		job.setWorkdir("D:/workspace/appwebtest");;
		String cmdline=generator.generateScript(bean, job);
		String expected="R --no-save<<'__INTERNAL_SCRIPT'\n"
			+"x<-c(5);\n"
			+"y<-c(6);\n"
			+"x+y\n"
			+"quit();\n"
			+"__INTERNAL_SCRIPT\n\n";
		System.out.println("|"+cmdline+"|");
		//assertEquals(expected, cmdline);
	}

}
